#script1902.py - Move Game Image
#Written by <Insert your Name>
# 
##########################################
#
##### Import Modules & Variables ######
import pygame			#Import PyGame library
import sys			#Import System module
#
from pygame.locals import *	#Load PyGame constants
#
pygame.init()			#Initialize PyGame
#
# Set up the Game Screen ################
#
ScreenSize = ScreenWidth,ScreenHeight = 1000,700
GameScreen=pygame.display.set_mode(ScreenSize)
#
# Set up the Game Color ################
#
blue = 0,0,255
#
# Set up the Game Image Graphics #######
GameImage="/usr/share/raspberrypi-artwork/raspberry-pi-logo.png"
GameImageGraphic=pygame.image.load(GameImage).convert_alpha()
# Resize image (make smaller)  
GameImageGraphic=pygame.transform.scale(GameImageGraphic,(75,75))
#
GameImageLocation=GameImageGraphic.get_rect()  #Current location
#
ImageOffset=[5,5]  #Moving speed
# 
# Set up the Game Sound ################
ClickSound=pygame.mixer.Sound('/home/pi/python_games/match1.wav')
#
#
###### Play the Game ###################
#
while True:
	for event in pygame.event.get():
		if event.type in (QUIT,MOUSEBUTTONDOWN):
			if GameImageLocation.collidepoint(pygame.mouse.get_pos()):
				ClickSound.play()
				pygame.time.delay(300)
				sys.exit()
	#Move game image
	GameImageLocation=GameImageLocation.move(ImageOffset)
	#Keep game image on screen
	if GameImageLocation.left < 0 or GameImageLocation.right > ScreenWidth:
		ImageOffset[0] = -ImageOffset[0]
		#Speed it up
		if ImageOffset[1] < 0:
			ImageOffset[1] = ImageOffset[1] - 1
		else:
			ImageOffset[1] = ImageOffset[1] + 1
		#
	if GameImageLocation.top < 0 or GameImageLocation.bottom > ScreenHeight:
		ImageOffset[1] = -ImageOffset[1]
		#Speed it up
		if ImageOffset[0] < 0:
			ImageOffset[0] = ImageOffset[0] - 1
		else:
			ImageOffset[0] = ImageOffset[0] + 1
		#
	#Draw screen images
	GameScreen.fill(blue)
	GameScreen.blit(GameImageGraphic,GameImageLocation)
	#Update game screen
	pygame.display.update()
#



